#include "yzrutil.h"
#include "Util.h"
#include "FloatBuffer.h"

namespace yzrilyzr_util{
	FloatBuffer *FloatBuffer::allocate(int size){
		FloatBuffer *buf=new FloatBuffer();
		buf->buffer=new float[size]();
		buf->icapacity=size;
		buf->limiter=size;
		buf->pointer=0;
		return buf;
	}
	FloatBuffer::~FloatBuffer(){
		std::cout<<"delete"<<std::endl;
		delete buffer;
	}
	void FloatBuffer::position(int p){
		pointer=p;
	}
	int FloatBuffer::position(){
		return pointer;
	}
	void FloatBuffer::limit(int p){
		limiter=p;
	}
	int FloatBuffer::limit(){
		return limiter;
	}
	void FloatBuffer::flip(){
		limiter=pointer;
		pointer=0;
	}
	float FloatBuffer::get(int p){
		if(p<0||p>=limiter)throw "BufferUnderFlowException";
		return buffer[p];
	}
	float FloatBuffer::get(){
		float f=get(pointer++);
		return f;
	}
	void FloatBuffer::put(float v){
		put(pointer++, v);
	}
	void FloatBuffer::put(int p, float v){
		if(p<0||p>=limiter)throw "BufferUnderFlowException";
		buffer[p]=v;
	}
	void FloatBuffer::clear(){
		pointer=0;
		limiter=icapacity;
	}
	int FloatBuffer::capacity(){
		return icapacity;
	}
}